<template>
  <!-- aria-hidden: 让这个元素对浏览器隐藏 -->
  <svg
    :class="svgClass"
    :style="{ color, width, height }"
    aria-hidden="true"
    v-bind="$attrs"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>
<script lang="ts" setup>
import { computed } from "vue";

const props = defineProps({
  prefix: {
    type: String,
    default: "#icon-",
  },
  name: {
    type: String,
    required: true,
  },
  className: {
    type: String,
    default: "",
  },
  color: {
    type: String,
    default: "",
  },
  height: {
    type: String,
    default: "",
  },
  width: {
    type: String,
    default: "",
  },
});

const iconName = computed(() => `${props.prefix}${props.name}`);
const svgClass = computed(() => {
  let className = props.className ? `icon-${props.className}` : "";
  return ["svg-icon", className];
});
</script>

<style scoped>
.svg-icon {
  width: 1.3em;
  height: 1.3em;
  overflow: hidden;
  vertical-align: -0.3em;
  fill: currentcolor;
}
</style>
